package com.chen.pfm.entity;

import com.chen.pfm.ResourceTable;
import ohos.data.orm.OrmObject;
import ohos.data.orm.annotation.Entity;
import ohos.data.orm.annotation.PrimaryKey;
import ohos.data.rdb.ValuesBucket;

@Entity(tableName = "classify",ignoredColumns = "Image")
public class Classify extends OrmObject {
    @PrimaryKey
    private String cid;

    private String cname;

    private int ctype = -1;

    private int uid = -1;

    private String cctime;
    //忽略这个图标映射
    private int Image = ResourceTable.Media_class_default;


    public Classify() {

    }

    public Classify(String cid, String cname, int ctype, int uid, String cctime, int image) {
        this.cid = cid;
        this.cname = cname;
        setCtype(ctype);
        this.uid = uid;
        this.cctime = cctime;
        Image = image;
    }

    public String getCid() {
        return cid;
    }

    public void setCid(String cid) {
        this.cid = cid;
    }

    public String getCname() {
        return cname;
    }

    public void setCname(String cname) {
        this.cname = cname;
    }

    public int getCtype() {
        return ctype;
    }

    public void setCtype(int ctype) {
        this.ctype = ctype;
        //设置映射图标
        setImage(getIconCode(ctype));
    }
    public int getCtype_1(){
        return ctype/10000;
    }
    public int getCtype_2(){
        return (ctype%10000)/1000;
    }
    public int getCtype_3(){
        return ctype%10;
    }
    public int getUid() {
        return uid;
    }

    public void setUid(int uid) {
        this.uid = uid;
    }

    public String getCctime() {
        return cctime;
    }

    public void setCctime(String cctime) {
        this.cctime = cctime;
    }

    public int getImage() {
        return Image;
    }

    public void setImage(int image) {
        Image = image;
    }

    @Override
    public String toString() {
        return "Classify{" +
                "cid='" + cid + '\'' +
                ", cname='" + cname + '\'' +
                ", ctype=" + ctype +
                ", uid=" + uid +
                ", cctime='" + cctime + '\'' +
                ", Image=" + Image +
                '}';
    }

    public static int getIconCode(int ctype) {
        int image = 0;
        image = ResourceTable.Media_class_default;
        int userdefined = (ctype % 10000) / 1000;
        int i = ctype / 10000, j = ctype % 1000;
        if (userdefined != 0) {
            switch (ctype%10) {
                case 0://铜币0
                    image = ResourceTable.Media_class_4_copper_0;
                    break;
                case 1://铜币1
                    image = ResourceTable.Media_class_4_copper_1;
                    break;
                case 2://铜币2
                    image = ResourceTable.Media_class_4_copper_2;
                    break;
                case 3://铜币3
                    image = ResourceTable.Media_class_4_copper_3;
                    break;
                case 4://铜币4
                    image = ResourceTable.Media_class_4_copper_4;
                    break;
                default:
                    image = ResourceTable.Media_class_default;
                    break;
            }

        }else if (i == 1) {//支出
            switch (j) {
                case 1://购物消费
                    image = ResourceTable.Media_class_1_shopping;
                    break;
                case 2://食品餐饮
                    image = ResourceTable.Media_class_1_catering;
                    break;
                case 3://交通出行
                    image = ResourceTable.Media_class_1_transportation;
                    break;
                case 4://休闲娱乐
                    image = ResourceTable.Media_class_1_entertainment;
                    break;
                case 5://居家生活
                    image = ResourceTable.Media_class_1_homelife;
                    break;
                case 6://文化教育
                    image = ResourceTable.Media_class_1_education;
                    break;
                case 7://送礼人情
                    image = ResourceTable.Media_class_1_gift;
                    break;
                case 8://医疗健康
                    image = ResourceTable.Media_class_1_medical;
                    break;
                case 9://理财支出
                    image = ResourceTable.Media_class_1_financial;
                    break;
                case 10://慈善捐赠
                    image = ResourceTable.Media_class_1_donation;
                    break;
                case 11://其他
                    image = ResourceTable.Media_class_1_else;
                    break;
                default:
                    image = ResourceTable.Media_class_default;
                    break;
            }

        } else if (ctype / 10000 == 2) {//收入
            switch (j) {
                case 1://工资
                    image = ResourceTable.Media_class_2_salary;
                    break;
                case 2://礼金人情
                    image = ResourceTable.Media_class_2_gift;
                    break;
                case 3://中奖
                    image = ResourceTable.Media_class_2_prize;
                    break;
                case 4://奖金
                    image = ResourceTable.Media_class_2_performancebonus;
                    break;
                case 5://补贴
                    image = ResourceTable.Media_class_2_subsidy;
                    break;
                case 6://报销
                    image = ResourceTable.Media_class_2_reimburse;
                    break;
                case 7://二手闲置
                    image = ResourceTable.Media_class_2_secondhand;
                    break;
                case 8://理财盈利
                    image = ResourceTable.Media_class_2_financialincome;
                    break;
                case 9://兼职外块
                    image = ResourceTable.Media_class_2_parttime;
                    break;
                case 10://其他
                    image = ResourceTable.Media_class_1_else;
                    break;
                default:
                    image = ResourceTable.Media_class_default;
                    break;
            }

        } else if (ctype / 10000 == 3) {//资产
            switch (j) {
                case 1://现金
                    image = ResourceTable.Media_class_3_cash;
                    break;
                case 2://虚拟账号
                    image = ResourceTable.Media_class_3_virtual;
                    break;
                case 3://借记卡
                    image = ResourceTable.Media_class_3_bankcard;
                    break;
                case 4://信用卡
                    image = ResourceTable.Media_class_3_creditcard;
                    break;
                case 5://基金股票
                    image = ResourceTable.Media_class_3_investment;
                    break;
                case 6://负债
                    image = ResourceTable.Media_class_3_debts;
                    break;
                case 7://借出
                    image = ResourceTable.Media_class_3_creditor;
                    break;
                default:
                    image = ResourceTable.Media_class_default;
                    break;
            }
        } else {
            image = ResourceTable.Media_class_1_else;
        }

        return image;

    }
    public Classify getObjectfromValues(ValuesBucket valuesBucket) {

        this.cid = valuesBucket.getString("cid");
        this.cname = valuesBucket.getString("cname");
        this.ctype = valuesBucket.getInteger("ctype");
        this.uid = valuesBucket.getInteger("uid");
        this.cctime = valuesBucket.getString("cctime");
        return this;
    }

    public ValuesBucket getValuesBucketfromObject() {
        ValuesBucket valuesBucket = new ValuesBucket();
        valuesBucket.putString("cid", cid);
        valuesBucket.putString("cname", cname);
        valuesBucket.putInteger("ctype", ctype);
        valuesBucket.putInteger("uid", uid);
        valuesBucket.putString("cctime", cctime);
        return valuesBucket;
    }
}

